Skip to content

fix: deserialize empty arrays as null for all Map and object fields - #442

Open
andrii-bodnar wants to merge 1 commit into
masterfrom
fix/empty-array-coercion
Open

andrii-bodnar wants to merge 1 commit into
masterfrom
fix/empty-array-coercion

Conversation

@andrii-bodnar

Copy link
Copy Markdown
Member

The API sends some empty objects as [], so Map-typed fields like Project.fields, SourceString.fields, Concept.fields, Term.fields and User.fields fail with MismatchedInputException. Until now we fixed this one field at a time with @JsonDeserialize(using = EmptyArrayToNullDeserializer.class), and new fields kept slipping through.

Changes

  • Configure Jackson on the shared cleanObjectMapper to read [] as null for every Map and POJO field. Mappers created with copy() inherit the setting, so custom deserializers get it too. Non-empty arrays still fail, and List fields are unchanged.
  • Remove the 20 per-field EmptyArrayToNullDeserializer annotations, which the setting now covers.
  • Deprecate EmptyArrayToNullDeserializer instead of removing it, for backward compatibility.
  • Update AGENTS.md: new deserializers should build their mapper from cleanObjectMapper instead of annotating fields.
  • Add EmptyArrayCoercionTest, which covers the five fields from the issue, ProjectSettings objects, and regression checks.

Closes #441

🤖 Generated with Claude Code

The API sends some empty objects as [], which broke Map-typed fields such
as Project.fields, SourceString.fields, Concept.fields, Term.fields and
User.fields. Configure Jackson coercion on the shared mapper so [] reads
as null for every Map and POJO field, and drop the per-field
EmptyArrayToNullDeserializer annotations it replaces. The deserializer
class is kept and deprecated for backward compatibility.

Closes #441

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* for every Map and POJO field
*/
@Deprecated
public class EmptyArrayToNullDeserializer extends StdDeserializer<Object> implements ContextualDeserializer {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we use it anywhere? can we delete it?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Project.fields fails to deserialize when API returns an empty array

3 participants